<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="上级用户id">
            <el-input v-model="form.parentId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="推送标识">
            <el-input v-model="form.registrationId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="项目账号">
            <el-input v-model="form.username" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="手机号">
            <el-input v-model="form.account" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="form.password" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="头像">
            <el-input v-model="form.headIcon" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="昵称">
            <el-input v-model="form.nickname" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="背景墙">
            <el-input v-model="form.backgroundWall" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="签名">
            <el-input v-model="form.sign" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="生日，年月日">
            <el-input v-model="form.birthday" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="性别 0男，1女">
            <el-input v-model="form.sex" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="邀请码">
            <el-input v-model="form.code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否删除：0否，1是">
            <el-input v-model="form.isDelete" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="createTime">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="id" />
        <el-table-column v-if="columns.visible('parentId')" prop="parentId" label="上级用户id" />
        <el-table-column v-if="columns.visible('registrationId')" prop="registrationId" label="推送标识" />
        <el-table-column v-if="columns.visible('username')" prop="username" label="项目账号" />
        <el-table-column v-if="columns.visible('account')" prop="account" label="手机号" />
        <el-table-column v-if="columns.visible('password')" prop="password" label="密码" />
        <el-table-column v-if="columns.visible('headIcon')" prop="headIcon" label="头像" />
        <el-table-column v-if="columns.visible('nickname')" prop="nickname" label="昵称" />
        <el-table-column v-if="columns.visible('backgroundWall')" prop="backgroundWall" label="背景墙" />
        <el-table-column v-if="columns.visible('sign')" prop="sign" label="签名" />
        <el-table-column v-if="columns.visible('birthday')" prop="birthday" label="生日，年月日">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.birthday) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('sex')" prop="sex" label="性别 0男，1女" />
        <el-table-column v-if="columns.visible('code')" prop="code" label="邀请码" />
        <el-table-column v-if="columns.visible('isDelete')" prop="isDelete" label="是否删除：0否，1是" />
        <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="createTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','user:edit','user:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudUser from '@/api/web/user'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from "@/components/material";

// crud交由presenter持有
const defaultCrud = CRUD({ title: '用户|农户账号', url: 'web/user', sort: 'id,desc', crudMethod: { ...crudUser }})
const defaultForm = { id: null, parentId: null, registrationId: null, username: null, account: null, password: null, headIcon: null, nickname: null, backgroundWall: null, sign: null, birthday: null, sex: null, code: null, isDelete: null, createTime: null }
export default {
  name: 'User',
  components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      
      permission: {
        add: ['admin', 'user:add'],
        edit: ['admin', 'user:edit'],
        del: ['admin', 'user:del']
      },
      rules: {
      }    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
  }
}



</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
